home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_11 / a11_1.m next >
Encoding:
Text File  |  1994-06-05  |  1.6 KB  |  65 lines  |  [MATS/MATL]

  1. echo off;
  2. % NUMERICAL METHODS: MATLAB Programs, (c) John H. Mathews 1994
  3. % To accompany the text:
  4. % NUMERICAL METHODS for Mathematics, Science and Engineering, 2nd Ed, 1992
  5. % Prentice Hall, Englewood Cliffs, New Jersey, 07632, U.S.A.
  6. % This free software is complements of the author.
  7.  
  8. % Algorithm 11.1 (Power Method).
  9. % Section    11.2,    The Power Method, Page 557
  10. echo on; clc; format long; hold off; clear
  11.  
  12. % POWER METHOD FOR FINDING AN EIGEN-PAIR
  13.  
  14. % Assume that A is an n by n real matrix and that it
  15.  
  16. % has a full set of eigenvectors  V , V  ,..., V .
  17. %                                  1   2        n
  18.  
  19. % The power method of iteration is used to find the
  20.  
  21. % dominant eigenvalue and its corresponding eigenvector.
  22.  
  23. % Remark. power.m is used for Algorithm 11.1
  24.  
  25. pause % Press any key to continue.
  26.  
  27. clc;
  28.  
  29. % Iteration will continue until each coordinate of the
  30.  
  31. % eigenvector has converged with an error less than
  32.  
  33. % epsilon or the maximum number of iterations is reached.
  34.  
  35. % Place the matrix in   A
  36.  
  37. % Place the matrix in  A  and  starting vector in  X.
  38.  
  39. % Place the tolerance in   epsilon
  40.  
  41. % Place the maximum number of iterations in  max1
  42.  
  43. A = [ 0    11    -5;
  44.      -2    17    -7;
  45.      -4    26   -10];
  46.  
  47. [n,n] = size(A);
  48. X = ones(n,1);
  49. epsilon = 1e-14;
  50. max1 = 100;
  51.  
  52. [lambda,V] = power(A,X,epsilon,max1,1)
  53.  
  54. pause % Press any key to continue.
  55.  
  56. clc;
  57. Mx1 = 'Implementation of the power method.';
  58. Mx2 = 'The matrix  A  is: ';
  59. Mx3 = 'The dominant eigenvalue of  A  is: ';
  60. Mx4 = 'The dominant eigenvector of  A  is: ';
  61. clc,echo off,diary output,...
  62. disp(''),disp(Mx1),disp(''),disp(Mx2),disp(A),...
  63. disp(Mx3),disp(lambda),disp(Mx4),disp(V),...
  64. diary off,echo on
  65.